$(function () {
    
    //获取url中的参数
    var expertId = getQueryString("expertId");
    console.log(expertId);
    //根据id从数据库中获取修改前的值
    $.post(
        "/citrusmonitor/expert.do?method=findExpertById&expertId="+expertId,

        function (data) {
         $("#expert_id").val(data.expertId),
	     $("#work_field").val(data.workField),
	     $("#password").val(data.password),
	     $("#introduction").val(data.introduction),
	     $("#work_place").val(data.workPlace),
         $("#email").val(data.email),
         $("#expert_name").val(data.expertName),
	     $("#img_path").val(data.imgPath)
        },
        "json"
    );
    //edit按钮绑定事件
    $("#edit").click(function () {
    	
    	 var formData = new FormData(); 
    	 formData.set("expertId",$("#expert_id").val());
    		formData.set("expertName",$("#expert_name").val());
    		formData.set("password",$("#password").val());
    		formData.set("workPlace",$("#work_place").val());
    		formData.set("workField",$("#work_field").val());
    		formData.set("introduction",$("#introduction").val());
    		formData.set("email",$("#email").val());
    		formData.set("imgPath", document.getElementById("img_path").files[0]);
//    		formData.set("imgPath",$("#img_path").val());
    	    $.ajax({
    	        url: "/citrusmonitor/expert.do?method=modify",
    	        type: "post",
    	        data:formData, 
    	        processData:false, 
    	        contentType:false, 
    	        /*data: {
    	            "expertName": $("#expert_name").val(),
    	            "password": $("#password").val(),
    	            "workPlace": $("#work_place").val(),
    	            "imgPath": $("#img_path").val(),
    	            "introduction": $("#introduction").val(),
    	            "email": $("#email").val(),
    	            "imgPath": $("#img_path").val()
    	        },*/
    	        dataType: "json",
    	        success: function (msg) {
    	        	console.log(msg)
    	            if (msg.status==1) {
    	                alert("修改信息成功");
    	                window.location.href="show.html";
    	            } else {
    	                alert("修改信息失败" );
    	            }
    	        },
    	        error:function(){
    	            alert("资源加载失败！！！");
    	        }
    	    })
//
//        $.post(
//            "/citrusmonitor/expert.do?method=modify",
//            {
//            	"expertId": $("#expert_id").val(),
//                "workField": $("#work_field").val(),
//                "password": $("#password").val(),
//                "introduction": $("#introduction").val(),
//                "workPlace": $("#work_place").val(),
//                "email": $("#email").val(),
//                "expertName": $("#expert_name").val(),
//                "imgPath": $("#img_path").val()
//            },
//           function(res){
//                console.log(res);
//                res = JSON.parse(res);
//                if(res.status==1){
//                    alert("信息提示修改成功");
//                }else{
//                    alert("信息提示修改失败");
//                }}
//        )
    })
})

function getQueryString(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    console.log(reg );
    var r = window.parent.document.getElementById("rightframe").contentWindow.location.search.substr(1).match(reg);
    if(r!=null){
        return  unescape(r[2]);
    }
    return null;
}
